define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'money/change/index' + location.search,
                    // add_url: 'money/change/add',
                    // edit_url: 'money/change/edit',
                    // del_url: 'money/change/del',
                    // multi_url: 'money/change/multi',
                    import_url: 'money/change/import',
                    table: 'money_change',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        // {field: 'order_num', title: __('Order_num'), operate: 'LIKE'},
                        {field: 'communitys.name', title: __('相关社区')},
                        {field: 'lists.name', title: __('物资名称')},
                        {
                            field: 'moneytype',
                            title: __('Moneytype'),
                            searchList: {"1": __('耗材'), "2": __('借出')},
                            formatter: Table.api.formatter.status
                        },
                        {field: 'dlists.name', title: __('部门')},
                        {
                            field: 'change_type',
                            title: __('Change_type'),
                            searchList: {
                                "1": __('入库登记'),
                                "2": __('物资出库'),
                                "3": __('物资出借'),
                                "4": __('归还物资'),
                                "5": __('库存盘点')
                            },
                            formatter: Table.api.formatter.status
                        },
                        {
                            field: 'record_type', title: __('Record_type'),
                            searchList: {
                                "0": __('减少'),
                                "1": __('增加'),
                            },
                            formatter: Table.api.formatter.status
                        },
                        {field: 'number', title: __('Number')},
                        {field: 'hasnumber', title: __('Hasnumber')},
                        // {field: 'relation_id', title: __('Relation_id')},
                        {
                            field: 'createtime',
                            title: __('Createtime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        // {
                        //     field: 'status',
                        //     title: __('Status'),
                        //     searchList: {"1) unsigne": __('1) unsigne')},
                        //     formatter: Table.api.formatter.status
                        // },
                        // {field: 'op', title: __('Op'), operate: 'LIKE'},
                        {field: 'remark', title: __('Remark'), operate: 'LIKE'},
                        // {
                        //     field: 'operate',
                        //     title: __('Operate'),
                        //     table: table,
                        //     events: Table.api.events.operate,
                        //     formatter: Table.api.formatter.operate
                        // }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
